//
//  AppDelegate+InitConfig.m
//  McRemote
//
//  Created by Magic on 1/30/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "AppDelegate+InitConfig.h"
#import "Group.h"
#import "Command.h"
#import "ModelManager.h"
#import "FileManager.h"

@implementation AppDelegate (InitConfig)

- (void)firstTimeUsageConfig
{
    BOOL notFirstTime  = [[NSUserDefaults standardUserDefaults] boolForKey:@"NotFirstTimeUsage"];
    
    
    if (!notFirstTime) {
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"DefaultCommands" ofType:@"plist"];
                
        NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:path];
        
        
        NSArray *general = [dic objectForKey:@"General"];        
        Group *group = [[ModelManager sharedManager] addGroupWithName:@"General"];        
        for (NSDictionary *command in general) {
            [[ModelManager sharedManager] addCommandWithGroup:group editable:NO properties:command];
        }
                                                                      
        
        NSArray *app = [dic objectForKey:@"App"];
        Group *appGroup = [[ModelManager sharedManager] addGroupWithName:@"App"];        
        for (NSDictionary *command in app) {
            [[ModelManager sharedManager] addCommandWithGroup:appGroup editable:NO properties:command];
        }
        
        NSArray *finder = [dic objectForKey:@"Finder"];
        Group *finderGroup = [[ModelManager sharedManager] addGroupWithName:@"Finder"];        
        for (NSDictionary *command in finder) {
            [[ModelManager sharedManager] addCommandWithGroup:finderGroup editable:NO properties:command];
        }
        
        NSArray *iTunes = [dic objectForKey:@"iTunes"];
        Group *iTunesGroup = [[ModelManager sharedManager] addGroupWithName:@"iTunes"];        
        for (NSDictionary *command in iTunes) {
            [[ModelManager sharedManager] addCommandWithGroup:iTunesGroup editable:NO properties:command];
        }
        
        
        //write finder icon to document
//        NSString *finder_icon_path = [[NSBundle mainBundle] pathForResource:@"Finder_dock" ofType:@"png"];
//        NSData *finder_icon_data = [NSData dataWithContentsOfFile:finder_icon_path];
//        [[FileManager sharedManager] writeToDocument:finder_icon_data fileName:@"Finder" extension:@"png"];
        
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NotFirstTimeUsage"];
    }

        
    [[ModelManager sharedManager] loadAllGroups];
        

}

@end
